package cn.iocoder.yudao.module.alipay.service.infoproduction;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.alipay.controller.admin.infoproduction.vo.*;
import cn.iocoder.yudao.module.alipay.dal.dataobject.infoproduction.InfoProductionDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.alipay.convert.infoproduction.InfoProductionConvert;
import cn.iocoder.yudao.module.alipay.dal.mysql.infoproduction.InfoProductionMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.alipay.enums.ErrorCodeConstants.*;

/**
 * 作品 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class InfoProductionServiceImpl implements InfoProductionService {

    @Resource
    private InfoProductionMapper infoProductionMapper;

    @Override
    public Long createInfoProduction(InfoProductionCreateReqVO createReqVO) {
        // 插入
        InfoProductionDO infoProduction = InfoProductionConvert.INSTANCE.convert(createReqVO);
        infoProductionMapper.insert(infoProduction);
        // 返回
        return infoProduction.getId();
    }

    @Override
    public void updateInfoProduction(InfoProductionUpdateReqVO updateReqVO) {
        // 校验存在
        validateInfoProductionExists(updateReqVO.getId());
        // 更新
        InfoProductionDO updateObj = InfoProductionConvert.INSTANCE.convert(updateReqVO);
        infoProductionMapper.updateById(updateObj);
    }

    @Override
    public void deleteInfoProduction(Long id) {
        // 校验存在
        validateInfoProductionExists(id);
        // 删除
        infoProductionMapper.deleteById(id);
    }

    private void validateInfoProductionExists(Long id) {
        if (infoProductionMapper.selectById(id) == null) {
            throw exception(INFO_PRODUCTION_NOT_EXISTS);
        }
    }

    @Override
    public InfoProductionDO getInfoProduction(Long id) {
        return infoProductionMapper.selectById(id);
    }

    @Override
    public List<InfoProductionDO> getInfoProductionList(Collection<Long> ids) {
        return infoProductionMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<InfoProductionDO> getInfoProductionPage(InfoProductionPageReqVO pageReqVO) {
        return infoProductionMapper.selectPage(pageReqVO);
    }

    @Override
    public List<InfoProductionDO> getInfoProductionList(InfoProductionExportReqVO exportReqVO) {
        return infoProductionMapper.selectList(exportReqVO);
    }

    @Override
    public List<InfoProductionDO> getListByTypeId(String typeId) {
        return infoProductionMapper.getListByTypeId(typeId);
    }

}
